//
//  DKAuthHomeLoanCell.m
//  DanKU
//
//  Created by 吴斌 on 2023/11/9.
//

#import "DKAuthHomeLoanCell.h"
#import "DKHomeAuthLoanHeadView.h"
#import "DKAuthHomeLoanSigleCell.h"
static NSString * DKAuthHomeLoanCellId = @"DKAuthHomeLoanCellId";
@interface DKAuthHomeLoanCell()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)DKHomeAuthLoanHeadView * dk_HomeAuthLoanHeadView;
@property (nonatomic, strong)UITableView * dk_AuthHomeLoanTableView;
@end
@implementation DKAuthHomeLoanCell
+ (instancetype)authHomeLoanCell:(UITableView *)tableView{
    DKAuthHomeLoanCell * dk_AuthHomeLoanCell = [tableView dequeueReusableCellWithIdentifier:DKAuthHomeLoanCellId];
    if (!dk_AuthHomeLoanCell) {
        dk_AuthHomeLoanCell = [[DKAuthHomeLoanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DKAuthHomeLoanCellId];
    }
    dk_AuthHomeLoanCell.backgroundColor = [UIColor clearColor];
    dk_AuthHomeLoanCell.selectionStyle = UITableViewCellSelectionStyleNone;
    dk_AuthHomeLoanCell.accessoryType = UITableViewCellAccessoryNone;
    return dk_AuthHomeLoanCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    WeakSelf(self)
    self.dk_HomeAuthLoanHeadView = [[DKHomeAuthLoanHeadView alloc] init];
    [self.contentView addSubview:self.dk_HomeAuthLoanHeadView];
    [self.dk_HomeAuthLoanHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(115)));
    }];
    self.dk_HomeAuthLoanHeadView.MsgAlertGoBlock = ^{
        if(weakSelf.MsgAlertGoBlock){
            weakSelf.MsgAlertGoBlock();
        }
    };
    
    self.dk_AuthHomeLoanTableView = [[UITableView alloc] init];
    self.dk_AuthHomeLoanTableView.backgroundColor = UIColor.clearColor;
    self.dk_AuthHomeLoanTableView.delegate = self;
    self.dk_AuthHomeLoanTableView.dataSource = self;
    self.dk_AuthHomeLoanTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.dk_AuthHomeLoanTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    self.dk_AuthHomeLoanTableView.showsVerticalScrollIndicator = NO;
    [self.contentView addSubview:self.dk_AuthHomeLoanTableView];
    [self.dk_AuthHomeLoanTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(self.dk_HomeAuthLoanHeadView.mas_bottom);
        make.bottom.equalTo(@(DK_IsWidthScale(0)));
    }];
}
-(void)setDk_OrderListMdl:(DKOrderListModel *)dk_OrderListMdl{
    _dk_OrderListMdl = dk_OrderListMdl;
    [self.dk_AuthHomeLoanTableView reloadData];
    if(_dk_OrderListMdl.orderRecordList.count > 0 ){
        self.dk_HomeAuthLoanHeadView.hidden = NO;
        self.dk_HomeAuthLoanHeadView.dk_OrderListMdl = dk_OrderListMdl;
        [self.dk_HomeAuthLoanHeadView updateAuthLoan];
    }else{
        self.dk_HomeAuthLoanHeadView.hidden = YES;
    }
}
-(void)setAmount:(NSString *)amount{
    _amount = amount;
    self.dk_HomeAuthLoanHeadView.amount = amount;
}
#pragma mark -- UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dk_OrderListMdl.orderRecordList.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return DK_IsWidthScale(85);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DKAuthHomeLoanSigleCell * dk_AuthHomeLoanSigleCell = [DKAuthHomeLoanSigleCell authHomeLoanSigleCell:tableView];
    dk_AuthHomeLoanSigleCell.dk_OrderRecordListMdl = _dk_OrderListMdl.orderRecordList[indexPath.row];
    return dk_AuthHomeLoanSigleCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(self.MsgOrderDetailGoBlock){
        self.MsgOrderDetailGoBlock(_dk_OrderListMdl.orderRecordList[indexPath.row]);
    }
}
@end
